function PagerOrders(tableName, itemsPerPage) {
	this.tableName = tableName;
	this.itemsPerPage = itemsPerPage;
	this.currentPage = 1;
	this.pages = 0;
	this.inited = false;

	this.showRecords = function(from) {
		var rows = document.getElementById(tableName).rows;
		for ( var i = 0; i < rows.length; i++) {
			if (rows[i].className.indexOf("page" + (from) + (" ")) === -1)
				rows[i].style.display = 'none';
			else
				rows[i].style.display = '';
		}
	}

	this.showPage = function(pageNumber) {
		if (!this.inited) {
			alert("not initiated");
			return;
		}

		var oldPageAnchor = document.getElementById('pg' + this.currentPage);
		oldPageAnchor.className = 'pg-normal number';

		this.currentPage = pageNumber;
		var newPageAnchor = document.getElementById('pg' + this.currentPage);
		newPageAnchor.className = 'pg-selected';

		var from = (pageNumber - 1);
		var to = from + itemsPerPage - 1;
		this.showRecords(from, to);
	}

	this.prev = function() {
		if (this.currentPage > 1)
			this.showPage(this.currentPage - 1);
	}

	this.next = function() {
		if (this.currentPage < this.pages) {
			this.showPage(this.currentPage + 1);
		}
	}

	this.init = function() {
		var rows = document.getElementsByClassName('ordersTitle'); //document.getElementById(tableName).rows;
		var records = (rows.length - 1);
		this.pages = rows.length; // Math.ceil(records /
		// itemsPerPage);
		this.inited = true;
	}

	this.showPageNav = function(pagerName, positionId) {
		if (!this.inited) {
			alert("not initiated");
			return;
		}
		var element = document.getElementById(positionId);

		var pagerHtml = '<span onclick="'
				+ pagerName
				+ '.prev();" class="pg-normal navi"> &#171 Poprzednie </span><span>  </span>';
		for ( var page = 1; page <= this.pages; page++)
			pagerHtml += '<span id="pg' + page
					+ '" class="pg-normal number" onclick="' + pagerName
					+ '.showPage(' + page + ');">' + page
					+ '</span><span>  </span>';
		pagerHtml += '<span onclick="' + pagerName
				+ '.next();" class="pg-normal navi"> Nastepne &#187;</span>';

		element.innerHTML = pagerHtml;
	}
}

hidePageNav = function(positionId) {
	var element = document.getElementById(positionId);
	element.style.display = "none";
}

showAgainPageNav = function(positionId) {
	var element = document.getElementById(positionId);
	element.style.display = "";
}

groupAll = function(navBarPosition, orderTableName) {
	showAgainPageNav(navBarPosition);
	
	var actualPage = document.getElementsByClassName('pg-selected')[0].innerHTML;
	
	var rows = document.getElementById(orderTableName).rows;
	for ( var i = 0; i < rows.length; i++) {
		if (rows[i].className.indexOf("page" + (actualPage-1) + (" ")) === -1)
			rows[i].style.display = 'none';
		else
			rows[i].style.display = '';
	}

}

unGroupAll = function(navBarPosition, orderTableName) {
	hidePageNav(navBarPosition);

	var rows = document.getElementById(orderTableName).rows;
	for ( var i = 0; i < rows.length; i++) {
		rows[i].style.display = '';
	}
}
